﻿<Page x:Class="MediaLibrary.PlaylistPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:AMPLibrary.Controls;assembly=AMPLibrary"
    Title="PlaylistPage">
    
    <Grid MouseLeftButtonUp="OnMouseLeftButtonUp" MouseMove="OnMouseMove">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="165" />
            <ColumnDefinition Width="250" MinWidth="250" MaxWidth="250" />
            <ColumnDefinition Width="150*" />
        </Grid.ColumnDefinitions>
        
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>

        <StackPanel Grid.Column="0" Margin="0,0,6,0">
            <Button Name="newPlaylistButton" Click="newPlaylistButton_Click" Template="{StaticResource playlistButton}">new playlist</Button>
            <Button Name="newAutomaticPlaylistButton" Click="newAutomaticPlaylistButton_Click" Template="{StaticResource playlistButton}">new automatic playlist</Button>
        </StackPanel>

        <Grid Grid.Row="0" Grid.Column="1" Background="Black">
            <Grid.RowDefinitions>
                <RowDefinition Name="playlistExpanderRow" Height="*" />
            </Grid.RowDefinitions>

            <StackPanel>
                <Expander Name="myPlaylistsExpander" Header="my playlists" Foreground="White" MaxHeight="{Binding playlistExpanderRow.Height-28}" Height="{Binding playlistExpanderRow.Height-28}" Expanded="myPlaylistsExpander_Expanded">
                    <ListView x:Name="playlistListView"
                     Grid.Row="1"
                     BorderThickness="0"
                     Background="Black"
                     Foreground="White"
                     ItemContainerStyle="{DynamicResource selectedStyle}"
                     ItemTemplate="{StaticResource playlistListWhiteDataTemplate}"
                     SelectionChanged="playlistListBox_SelectionChanged"
                     ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                        <ListView.Padding>3</ListView.Padding>

                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem x:Name="addToNowPlayingMenuItem" Header="Add to Now Playing" Click="addToNowPlayingMenuItem_Click" />
                                <MenuItem x:Name="replaceNowPlayingMenuItem" Header="Replace Now Playing with Playlist" Click="replaceNowPlayingMenuItem_Click" />
                                <Separator />
                                <MenuItem x:Name="deletePlaylistMenuItem" Header="Delete Playlist" Click="deletePlaylistMenuItem_Click" />
                            </ContextMenu>
                        </ListView.ContextMenu>
                    </ListView>
                </Expander>

                <Expander Name="automaticPlaylistExpander" Header="automatic playlists" Foreground="White" MaxHeight="{Binding playlistExpanderRow.Height-56}" Height="{Binding playlistExpanderRow.Height-56}" Expanded="automaticPlaylistExpander_Expanded">
                    <ListView x:Name="automaticPlaylistListView"
                     Grid.Row="1"
                     BorderThickness="0"
                     Background="Black"
                     Foreground="White"
                     ItemContainerStyle="{DynamicResource selectedStyle}"
                     ItemTemplate="{StaticResource automaticPlaylistListWhiteDataTemplate}"
                     SelectionChanged="automaticPlaylistListView_SelectionChanged"
                     ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                        <ListView.Padding>3</ListView.Padding>
                    </ListView>
                </Expander>
            </StackPanel>
        </Grid>
        
        <GridSplitter ResizeDirection="Columns" Grid.Row="0" Grid.Column="1" Width="3" IsEnabled="False" Background="Gray" IsTabStop="False"  />

        <Rectangle 
                Grid.Column="2"
                Width="{Binding playlistColumn.Width}" 
                Height="{Binding playlistColumn.Height}" 
                Opacity=".8"
                StrokeThickness="4"
                Fill="Black">
        </Rectangle>
        
        <Grid x:Name="playlistGrid" Grid.Row="0" Grid.Column="2" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="28" />
                <RowDefinition x:Name="playlistRow" Height="*" />
                <RowDefinition x:Name="savePlaylistRow" Height="29" />
            </Grid.RowDefinitions>

            <Menu Grid.Row="0" Width="{Binding playlistColumn.Width}" Padding="0, 0, 0, 0" Background="Black" VerticalAlignment="Top" Height="26">
                <MenuItem Header="Playlist Options" Foreground="White" FontSize="14">
                    <MenuItem Header="Remove" Foreground="Black">
                        <MenuItem Header="Remove All" Click="removeAllMenuItem_OnClick" Foreground="Black" />
                        <MenuItem Header="Remove Selected" Click="removeSelectedMenuItem_OnClick" Foreground="Black" />
                        <MenuItem Header="Crop" Click="cropMenuItem_OnClick" Foreground="Black" />
                    </MenuItem>
                    <Separator />
                    <MenuItem Header="Select" Foreground="Black">
                        <MenuItem Header="Select All" Click="selectAllMenuItem_OnClick" Foreground="Black" />
                        <MenuItem Header="Invert Selection" Click="invertSelectionMenuItem_OnClick" Foreground="Black" />
                        <MenuItem Header="Clear Selection" Click="clearSelectionMenuItem_OnClick" Foreground="Black" />
                    </MenuItem>
                    <Separator />
                    <MenuItem Header="Sort by..." Foreground="Black">
                        <MenuItem Header="Title" Click="sortByTitleMenuItem_OnClick" Foreground="Black" />
                        <MenuItem Header="Path and Filename" Click="sortByPathMenuItem_OnClick" Foreground="Black" />
                        <Separator />
                        <MenuItem Header="Randomize List" Click="randomizeMenuItem_OnClick" Foreground="Black" />
                        <MenuItem Header="Reverse List" Click="reverseListMenuItem_OnClick" Foreground="Black" />
                    </MenuItem>
                </MenuItem>
            </Menu>
            
            <ListView x:Name="currentPlaylistListView" 
                Grid.Row="1" 
                SelectionMode="Extended" 
                ScrollViewer.CanContentScroll="False" 
                Background="Transparent"
                BorderBrush="Transparent"
                ScrollViewer.HorizontalScrollBarVisibility="Auto"
                ItemContainerStyle="{DynamicResource selectedStyle}"
                Mouse.PreviewMouseDown="nowPlayingListView_OnMouseLeftButtonDown"
                MouseLeftButtonDown="nowPlayingListView_OnMouseLeftButtonDown"
                MouseDoubleClick="currentPlaylistListView_MouseDoubleClick">               
            </ListView>
            
            <StackPanel Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0 0 6 6" >
                <Button x:Name="cancelChangesPlaylistButton" Width="100" Click="cancelChangesPlaylistButton_Click">Cancel Changes</Button>
                <Label> </Label>
                <Button x:Name="savePlaylistButton" Width="100" Click="savePlaylistButton_Click">Save Playlist</Button>
            </StackPanel>
        </Grid>

        <local:AutomaticPlaylistDetailsControl x:Name="automaticPlaylistDetails" Grid.Row="0" Grid.Column="2" Background="Transparent" />
        
        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,5,0,0" >
            <Button x:Name="refreshButton" Click="refreshButton_Click">Refresh Playlists</Button>
            <Label x:Name="playlistCountLabel">Playlists</Label>
        </StackPanel>
        
        <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0" >
            <Label x:Name="currentlyScanning" />
        </StackPanel>
    </Grid>
</Page>
